//
//  PersonalInformationTableViewCell.m
//  ChineseCollegeStudentsNetwork
//
//  Created by 刘喆 on 2018/5/11.
//  Copyright © 2018年 刘喆. All rights reserved.
//

#import "PersonalInformationTableViewCell.h"

@implementation PersonalInformationTableViewCell

#pragma mark - Init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self createSubviews];
    }
    return self;
}

#pragma mark - Setter

- (void)setType:(InformationType)type {
    
    switch (type) {
        case ISInformationType:
            _headerImgv.hidden = YES;
            [self.informationLbl setHidden:NO];
            [self.accessoryImgv  setHidden:NO];
            break;
        case ISHeaderType:
            _headerImgv.hidden = NO;
            [self.informationLbl setHidden:YES];
            [self.accessoryImgv  setHidden:YES];
            break;
            
        default:
            break;
    }
    
}

#pragma mark - Subviews
#pragma amrk layout subviews
- (void)layoutSubviewsInView {
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.equalTo(self);
    }];
    
    [_informationLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(80);
        make.width.mas_equalTo (kDeviceWidth - 120);
        make.centerY.equalTo(self);
    }];
    [_headerImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-24);
        make.width.height.mas_equalTo(44);
        make.centerY.equalTo(self);
    }];
    
    [_accessoryImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-20);
        make.width.height.mas_equalTo(10);
        make.centerY.equalTo(self);
    }];
    
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView).offset(1);
        make.right.mas_offset(0);
        make.width.mas_equalTo(self.contentView);
        make.height.mas_equalTo(.5);
    }];
    
}

#pragma mark create subviews
- (void)createSubviews {
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.informationLbl];
    [self.contentView addSubview:self.headerImgv];
    [self.contentView addSubview:self.accessoryImgv];
    [self.contentView addSubview:self.line];
    [self layoutSubviewsInView];
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = [UIFont systemFontOfSize:13];
            _titleLbl.textColor = kRGB(153, 153, 153, 1);
    }
    return _titleLbl;
}

- (UILabel *)informationLbl {
    if (!_informationLbl) {
        _informationLbl = [[UILabel alloc] init];
        _informationLbl.textColor = kRGB(153, 153, 153, 1);
        _informationLbl.textAlignment = NSTextAlignmentRight;
    }
    return _informationLbl;
} 
- (UIImageView *)headerImgv {
    if (!_headerImgv) {
        _headerImgv = [[UIImageView alloc] init];
        _headerImgv.image = [UIImage imageNamed:@"头像"];
    }
    return _headerImgv;
}

- (UIImageView *)accessoryImgv {
    if (!_accessoryImgv) {
        _accessoryImgv = [[UIImageView alloc] init];
        _accessoryImgv.image = [UIImage imageNamed:@"mine_arrow_r"];
    }
    return _accessoryImgv;
}

- (UILabel *)line {
    
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor grayColor];
    }
    
    return _line;
}

@end
